package com.lonely.api.shein;


import com.lonely.api.shein.config.HttpClientConfig;
import com.lonely.api.shein.service.SheinOpenSDKClient;
import com.lonely.api.shein.service.SheinOpenSDKClientImpl;

/**
 * 构建单例的 shein sdk实例
 */
public final class SheinOpenSDK {
    /**
     * create SheinOpenApi instance
     */
    private static volatile SheinOpenSDKClient instance;
    private static volatile HttpClientConfig config;


    /**
     * 根据httpclient配置生成 SheinOpenSDKClient实例对象(单例)
     *
     * @param appConfig
     * @return
     */
    public static SheinOpenSDKClient getInstance(HttpClientConfig appConfig) {
        if (appConfig == null) {
            throw new IllegalArgumentException("Config cannot be null");
        }

        if (instance == null || !appConfig.equals(config)) {
            synchronized (SheinOpenSDK.class) {
                if (instance == null || !appConfig.equals(config)) {
                    instance = new SheinOpenSDKClientImpl(appConfig);
                    config = appConfig;
                }
            }
        }
        return instance;
    }

    private SheinOpenSDK() {
    }
}
